import re
import os
import requests

source_page_html = requests.get('https://lfs.xry111.site/zh_CN/11.2/chapter03/packages.html').text
# print(source_page_html)
for link in re.findall(r'href=\s*"(http.+?)"', source_page_html):
    base_name = os.path.basename(link)
    if '.' not in base_name:
        continue
    if os.path.isfile(base_name) and os.path.getsize(base_name) > 0:
        continue
    print(link)
    try:
        resp = requests.get(link, timeout=10)
        if resp.status_code == 200:
            with open(base_name, 'wb') as fw:
                fw.write(resp.content)
            print(f'downloaded {base_name}')
    except:
        pass
